﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Abp.Application.Services.Dto;
using FutureApp.Orders.Dto;
using Abp.Domain.Repositories;
using Abp.UI;
using Abp.AutoMapper;
using Abp.Domain.Uow;
using FutureApp.Shop;
using FutureApp.Cms.Dto;
using System.Linq;
using Abp.Linq.Extensions;

namespace FutureApp.Orders
{
    /// <AppService/>
    public class OrdersAppService : FutureAppAppServiceBase, IOrdersAppService
    {
        private IRepository<OrderHead, Guid> headRepository { get; }

       private IRepository<OrderMain, Guid> mainRepository { get; }

        /// <constructor/>
        public OrdersAppService(
            IRepository<OrderHead, Guid> r1,
             IRepository<OrderMain, Guid> r2
        )
        {
            this.headRepository = r1;
           this.mainRepository = r2;

        }
        /// 提交申请
        public async Task CreateOrderHead(CreateOrderHeadInput input)
        {
            var entity = input.MapTo<OrderHead>();
            await this.headRepository.InsertAsync(entity);
        }
        /// 分期明细
        public async Task CreateOrderMain(CreateOrderMainInput input)
        {
            var entity = input.MapTo<OrderMain>();
            await this.mainRepository.InsertAsync(entity);
        }
        /// 获取个人用户审核进度表
        public ListResultDto<OrderHeadListOutput> GetListByTel(string tel)
        {
            var list = this.headRepository.GetAll().Where(e => e.SellTelephone == tel).ToList();
            return new ListResultDto<OrderHeadListOutput>(list.MapTo<List<OrderHeadListOutput>>());
        }
        /// 获取商户审核进度表
        public ListResultDto<OrderHeadListOutput> GetListByCreatorUserId(long creatorId)
        {
            var list = this.headRepository.GetAll().Where(e => e.CreatorUserId==creatorId).ToList();
            return new ListResultDto<OrderHeadListOutput>(list.MapTo<List<OrderHeadListOutput>>());
        }
    }
}
